import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:leader_help/utils/component/component.dart';
import 'package:leader_help/utils/util.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class HeadlinesPage extends GetView<HeadlinesController> {
  const HeadlinesPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HeadlinesController>(
      builder: (_) {
        return Scaffold(
          appBar: detailAppBar(context,
              title: '领导头条',
              bottom: PreferredSize(
                  child: TabBar(
                      controller: controller.state.tabCtrl,
                      padding: EdgeInsets.zero,
                      isScrollable: true,
                      indicatorColor: ColorsUtil.red,
                      indicatorSize: TabBarIndicatorSize.label,
                      labelColor: ColorsUtil.red,
                      unselectedLabelColor: ColorsUtil.title,
                      labelStyle: TextStyle(
                          color: ColorsUtil.red,
                          fontSize: 14.sp,
                          fontWeight: FontWeight.bold),
                      unselectedLabelStyle:
                          TextStyle(color: ColorsUtil.title, fontSize: 14.sp),
                      tabs: controller.state.headlinesTitles
                          .asMap()
                          .map(
                            (key, value) => MapEntry(
                              key,
                              Tab(
                                child: Text(value),
                                height: 30.r,
                              ),
                            ),
                          )
                          .values
                          .toList()),
                  preferredSize: Size.fromHeight(44.r))),
          body: SafeArea(
            child: TabBarView(
                controller: controller.state.tabCtrl,
                children: controller.state.headlinesTitles
                    .asMap()
                    .map(
                      (key, value) => MapEntry(
                        key,
                        HeadlinesListView(),
                      ),
                    )
                    .values
                    .toList()),
          ),
        );
      },
    );
  }
}
